package com.bootdo.system.service.impl;

import com.bootdo.common.utils.ConversionUtil;
import com.bootdo.system.vo.AttachedResume;
import com.bootdo.system.vo.EducationalExperience;
import com.bootdo.system.vo.OnlineResume;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.bootdo.system.dao.DlMemberDao;
import com.bootdo.system.domain.DlMemberDO;
import com.bootdo.system.service.DlMemberService;



@Service
public class DlMemberServiceImpl implements DlMemberService {
	@Autowired
	private DlMemberDao dlMemberDao;
	@Value("${upload.IP}")
	private String IP;
	
	@Override
	public DlMemberDO get(Integer memberId){
		return dlMemberDao.get(memberId);
	}
	
	@Override
	public List<DlMemberDO> list(Map<String, Object> map){
		return dlMemberDao.list(map);
	}
	
	@Override
	public int count(Map<String, Object> map){
		return dlMemberDao.count(map);
	}
	
	@Override
	public int save(DlMemberDO dlMember){
		return dlMemberDao.save(dlMember);
	}
	
	@Override
	public int update(DlMemberDO dlMember){
		if(dlMember.getAvatar() != null){
			String[] split = dlMember.getAvatar().split("/");
			dlMember.setAvatar(split[split.length-1]);
		}
		if(dlMember.getAvatar() != null){
			String[] split = dlMember.getAvatar().split("/");
			dlMember.setAvatar(split[split.length-1]);
		}
		return dlMemberDao.update(dlMember);
	}
	
	@Override
	public int remove(Integer memberId){
		return dlMemberDao.remove(memberId);
	}
	
	@Override
	public int batchRemove(Integer[] memberIds){
		return dlMemberDao.batchRemove(memberIds);
	}

	/**
	 * 功能描述: 获取在线简历
	 * @Param: [memberId]
	 * @Return: com.ncxhr.logic.vo.OnlineResume
	 * @Author: 况鑫威
	 * @Date: 2021/4/19
	 * @Time: 19:00
	 */
	@Override
	public OnlineResume getResume(Integer memberId) {
		OnlineResume resume = dlMemberDao.getResume(memberId);
		int a = -1;
		if(resume != null){
			//学历转换
			if(resume.getEducationalExperiences() != null){

				for (EducationalExperience educationalExperience : resume.getEducationalExperiences()) {
					//循环判断是哪一个学历
					for (int i = 1; i < 8; i++) {
						if (educationalExperience.getEducation() == i) {
							//通过数字获取对应的学历
							educationalExperience.setEducationText(EducationalExperience.EXPERIENCE[i]);
							if(a < i){
								a = i;
							}
						}
					}
//            if (educationalExperience.getGraduateYear() != null) {
//                //拼接出应届生
//                resume.setGraduates(educationalExperience.getGraduateYear().substring(2) );
//            }
				}
			}

			if(a != -1){
				resume.setEducationText(EducationalExperience.EXPERIENCE[a]);
			}


			//获取年龄
			Integer age = ConversionUtil.getAge(resume.getBirthday());
			resume.setAge(age);

			//头像拼接
			if(!resume.getAvatar().equals("")){
				resume.setAvatar(IP + "/upload/" + resume.getAvatar());
			}


			if(resume.getAttachedResumes() != null){
                //路径拼接附件简历路径
                for (AttachedResume attachedResume : resume.getAttachedResumes()) {
                    //IP加路径加文件名合成完整地址
                    attachedResume.setPath(IP + "/upload/" + attachedResume.getFileName());
                }
            }
		}

		return resume;
	}

}
